package com.xuecheng.checkcode.application.service.impl;

import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.checkcode.application.service.CodeApplication;
import com.xuecheng.checkcode.domain.model.vo.req.CheckCodeQry;
import com.xuecheng.checkcode.domain.model.vo.req.CheckCodeVerifyQry;
import com.xuecheng.checkcode.domain.model.vo.resp.CheckCodeResp;
import com.xuecheng.checkcode.domain.service.CheckCodeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-09-07  18:08
 */
@Service
public class CodeApplicationImpl implements CodeApplication {

    @Autowired
    private CheckCodeService checkCodeService;

    @Override
    public CheckCodeResp generateCheckCode(CheckCodeQry checkCodeQry) {
        if (Objects.isNull(checkCodeQry)){
            throw new XueChengPlusException("参数不能为空");
        }

        return checkCodeService.generateCheckCode(checkCodeQry);
    }

    @Override
    public Boolean verify(CheckCodeVerifyQry checkCodeVerifyQry) {
        if (Objects.isNull(checkCodeVerifyQry) || StringUtils.isEmpty(checkCodeVerifyQry.getCode())
         || StringUtils.isEmpty(checkCodeVerifyQry.getKey())){
            throw new XueChengPlusException("参数不能为空");
        }

        return checkCodeService.verify(checkCodeVerifyQry);
    }
}
